package com.jzh.eurekaclient.web;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {
    private static final Logger logger = LogManager.getLogger(UploadController.class);
    @PostMapping(value = "/uploadFile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String handleFileUpload(@RequestParam(value = "xiaomi",required = false)String xiaomi,@RequestParam(value = "file") MultipartFile file) {
        logger.info(xiaomi+"*************************"+file.getOriginalFilename());
        return xiaomi+"|"+file.getOriginalFilename();
    }
    @PostMapping(value = "/uploadFiles", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String handleFilesUpload(@RequestParam(value = "xiaomi",required = false)String xiaomi,@RequestParam(value = "files") MultipartFile[] files) {
        String fileStr="";
        for (MultipartFile file:files) {
            fileStr+=file.getOriginalFilename()+"|";
        }
        logger.info(xiaomi+"###########################"+fileStr);
        return xiaomi+"|"+fileStr;
    }
}
